From a2079dfb5ef16c88780bd8736fdd74520e3a2719 Mon Sep 17 00:00:00 2001 From: robertl Date: Tue, 8 Jun 2004 06:29:07 +0000 Subject: [PATCH] Add a new filter for sorting. Copyright updates. --- Makefile | 2 +- defs.h | 1 + filter_vecs.c | 8 +++- gpsutil.c | 25 ++++++++++-- gpx.c | 18 +++++++++ mkshort.c | 21 ++++++++++ sort.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 173 insertions(+), 5 deletions(-) create mode 100644 sort.c diff --git a/Makefile b/Makefile index 3608fbcf9..55f6ea293 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ FMTS=magproto.o gpx.o geo.o mapsend.o mapsource.o \ gpilots.o saroute.o navicache.o psitrex.o geoniche.o delgpl.o \ ozi.o nmea.o text.o html.o palmdoc.o -FILTERS=position.o duplicate.o arcdist.o polygon.o smplrout.o reverse_route.o +FILTERS=position.o duplicate.o arcdist.o polygon.o smplrout.o reverse_route.o sort.o JEEPS=jeeps/gpsapp.o jeeps/gpscom.o \ jeeps/gpsmath.o jeeps/gpsmem.o \ diff --git a/defs.h b/defs.h index 974e9dc1f..3fbe48bb3 100644 --- a/defs.h +++ b/defs.h @@ -118,6 +118,7 @@ typedef struct { typedef struct { geocache_type type; geocache_container container; + int id; /* The decimal cache number */ int diff; /* (multiplied by ten internally) */ int terr; /* (likewise) */ time_t exported; diff --git a/filter_vecs.c b/filter_vecs.c index 6453dc8de..772d7adf5 100644 --- a/filter_vecs.c +++ b/filter_vecs.c @@ -1,7 +1,7 @@ /* Describe vectors containing filter operations. - Copyright (C) 2002 Robert Lipe, robertlipe@usa.net + Copyright (C) 2002,2004 Robert Lipe, robertlipe@usa.net This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,6 +35,7 @@ extern filter_vecs_t arcdist_vecs; extern filter_vecs_t polygon_vecs; extern filter_vecs_t routesimple_vecs; extern filter_vecs_t reverse_route_vecs; +extern filter_vecs_t sort_vecs; static fl_vecs_t filter_vec_list[] = { @@ -73,6 +74,11 @@ fl_vecs_t filter_vec_list[] = { "reverse", "Reverse stops within routes", }, + { + &sort_vecs, + "sort", + "Rearrange waypoints by resorting", + }, { NULL, NULL, diff --git a/gpsutil.c b/gpsutil.c index 2ab25528c..21ffe1ba6 100644 --- a/gpsutil.c +++ b/gpsutil.c @@ -1,7 +1,23 @@ /* - * written by robertlipe@usa.net - */ + Access gpsutil files. + + Copyright (C) 2002, 2003, 2004 Robert Lipe, robertlipe@usa.net + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ #include "defs.h" #include "magellan.h" @@ -93,6 +109,7 @@ gpsutil_disp(const waypoint *wpt) { double lon,lat; const char *icon_token; + char *tdesc = str_utf8_to_ascii(wpt->description); icon_token = mag_find_token_from_descr(wpt->icon_descr); @@ -109,8 +126,10 @@ gpsutil_disp(const waypoint *wpt) lon < 0.0 ? 'W' : 'E', wpt->altitude, 'm', - wpt->description ? wpt->description : "", + wpt->description ? tdesc : "", icon_token); + + xfree(tdesc); } static void diff --git a/gpx.c b/gpx.c index 9d2dc3246..871aa8fc5 100644 --- a/gpx.c +++ b/gpx.c @@ -77,6 +77,7 @@ typedef enum { tt_wpt_time, tt_wpt_type, tt_wpt_urlname, + tt_cache, tt_cache_name, tt_cache_container, tt_cache_type, @@ -145,6 +146,7 @@ tag_mapping tag_path_map[] = { { tt_wpt_urlname, 0, "/gpx/wpt/urlname" }, { tt_wpt_sym, 0, "/gpx/wpt/sym" }, { tt_wpt_type, 1, "/gpx/wpt/type" }, + { tt_cache, 1, "/gpx/wpt/groundspeak:cache" }, { tt_cache_name, 1, "/gpx/wpt/groundspeak:cache/groundspeak:name" }, { tt_cache_container, 1, "/gpx/wpt/groundspeak:cache/groundspeak:container" }, { tt_cache_type, 1, "/gpx/wpt/groundspeak:cache/groundspeak:type" }, @@ -274,6 +276,19 @@ tag_cache_desc(const char ** attrv) } } +static void +tag_gs_cache(const char **attrv) +{ + const char **avp; + + cache_descr_is_html = 0; + for (avp = &attrv[0]; *avp; avp+=2) { + if (strcmp(avp[0], "id") == 0) { + wpt_tmp->gc_data.id = atoi(avp[1]); + } + } +} + static void start_something_else(const char *el, const char **attrv) { @@ -427,6 +442,9 @@ gpx_start(void *data, const char *el, const char **attr) case tt_unknown: start_something_else(el, attr); return; + case tt_cache: + tag_gs_cache(attr); + break; case tt_cache_log_wpt: if (opt_logpoint) tag_log_wpt(attr); diff --git a/mkshort.c b/mkshort.c index 7b653eb27..15d69bcea 100644 --- a/mkshort.c +++ b/mkshort.c @@ -1,3 +1,24 @@ +/* + Generate unique short names. + + Copyright (C) 2003, 2004 Robert Lipe, robertlipe@usa.net + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ + #include #include #include diff --git a/sort.c b/sort.c new file mode 100644 index 000000000..f84529a54 --- /dev/null +++ b/sort.c @@ -0,0 +1,103 @@ +/* + Arbitrary Sorting Filter(s) + + Copyright (C) 2004 Robert Lipe, robertlipe@usa.net + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ +#include "defs.h" + +extern queue waypt_head; + +typedef enum { + sm_unknown = 0, + sm_gcid, + sm_shortname, + sm_description +} sort_mode_; + +sort_mode_ sort_mode = sm_shortname; /* How are we sorting these? */ + +static char *opt_sm_gcid, *opt_sm_shortname, *opt_sm_description; + +static +arglist_t sort_args[] = { + {"gcid", &opt_sm_gcid, "Sort by numeric geocache ID", ARGTYPE_BOOL }, + {"shortname", &opt_sm_shortname, "Sort by waypoint short name", ARGTYPE_BOOL }, + {"description", &opt_sm_description, "Sort by waypoint description", ARGTYPE_BOOL }, + {0, 0, 0, 0} +}; + +static int +sort_comp(const void * a, const void * b) +{ + const waypoint *x1 = *(waypoint **)a; + const waypoint *x2 = *(waypoint **)b; + + switch (sort_mode) { + case sm_gcid: return x1->gc_data.id > x2->gc_data.id; + case sm_shortname: return strcmp (x1->shortname, x2->shortname); + case sm_description: return strcmp (x1->description, x2->description); + } +} + +void +sort_process(void) +{ + queue * elem, * tmp; + waypoint ** comp; + int i = 0, wc; + + wc = waypt_count(); + + comp = xcalloc(wc, sizeof(*comp)); + + QUEUE_FOR_EACH(&waypt_head, elem, tmp) { + comp[i] = (waypoint *)elem; + waypt_del(comp[i]); /* Pop this waypoint off the master Q */ + i++; + } + + qsort(comp, wc, sizeof(waypoint *), sort_comp); + + /* + * Now re-add the list back. + */ + for (i = 0; i < wc ; i++) { + waypt_add(comp[i]); + } + + if (comp) + xfree(comp); +} + +void +sort_init(const char *args) +{ + if (opt_sm_gcid) + sort_mode = sm_gcid; + if (opt_sm_shortname) + sort_mode = sm_shortname; + if (opt_sm_description) + sort_mode = sm_description; +} + +filter_vecs_t sort_vecs = { + sort_init, + sort_process, + NULL, + sort_args +}; -- 2.30.2